using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UpgradeStaticShield:Upgrade {

	float shieldCurrent;
	float timeAfterUpdate;

	public override void Update(object sender,WeaponEventArgs e) {
		base.Update(sender,e);
		timeAfterUpdate+=deltaTime;
		if(timeAfterUpdate>0.1f) timeAfterUpdate-=0.2f;
		else return;

		if(weapon.owner.rigidbody.velocity.sqrMagnitude>0.1) {

			if(weapon.owner.buffs[typeof(BuffDamageShield)].stacks!=0) {
				weapon.owner.buffs[typeof(BuffDamageShield)].stacks-=1;
				shieldCurrent-=1;
			} else shieldCurrent=0;

		} else {
			if(shieldCurrent>weapon.owner.buffs[typeof(BuffDamageShield)].stacks)
				shieldCurrent=weapon.owner.buffs[typeof(BuffDamageShield)].stacks;
			if(shieldCurrent<2.5) {
				shieldCurrent+=0.25f;
				weapon.owner.buffs[typeof(BuffDamageShield)].stacks+=0.25f;
			}
		}

	}

	public override void UnsubscribeEvents() {
		base.UnsubscribeEvents();
		weapon.owner.buffs[typeof(BuffDamageShield)].stacks-=shieldCurrent;
		shieldCurrent=0;
	}

}
